package com.sino.operation.service.business;

import com.sino.operation.peripheral.esc.request.CoreHead;
import com.sino.operation.peripheral.esc.request.core.EscCoreParam;
import com.sino.operation.peripheral.esc.request.core.body.EscBodyCore2006;
import com.sino.operation.peripheral.esc.response.core.EscCoreDto;
import com.sino.operation.peripheral.esc.response.core.body.EscResBody2006;
import com.sino.operation.util.EscRequestTestUtil;
import com.sino.operation.util.RestTemplateUtils;
import com.sino.operation.util.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * @Title: AccountChargeService1
 * @Description: 对公保证金、对公定期（通知）存款核心记账服务
 * @Author dengls
 * @date 2021/11/5 17:44
 */
@Service
@Slf4j
public class AccountChargeService2 {

    @Autowired
    private UrlUtil urlUtil;

    @Autowired
    private RestTemplateUtils restTemplateUtils;

    public EscCoreDto<EscResBody2006> queryDP2006(String journalNo, String escToken, String productCode, String bz) {
        String url = urlUtil.getCoreUrl("2006");
        EscCoreParam<EscBodyCore2006> escCoreParam = EscRequestTestUtil.getEscCoreParam(journalNo, "2006", escToken);
        EscBodyCore2006 escBodyCore2006 = EscBodyCore2006.builder().coreHead(CoreHead.builder().reqResFlg("req").build()).prodCode(productCode).ccyCodeNum(bz).build();
        escCoreParam.setEscBodyCore(escBodyCore2006);
        ResponseEntity<EscCoreDto<EscResBody2006>> post = restTemplateUtils
                .exchange(url, HttpMethod.POST,
                        new HttpEntity<>(escCoreParam),
                        new ParameterizedTypeReference<EscCoreDto<EscResBody2006>>() {
                        });
        return post.getBody();
    }
}
